#!/usr/bin/env bash
set -e

# TODO: Only install if needed, and if we install it, remove it when we are done.
pacman -S squashfs-tools --noconfirm

# Make the directory that will be extracted
mkdir /extract

# Build/copy all files to extract directory
mksquashfs / /extract/rootfs.squash -e /extract -e /sys -e /proc
cp /boot/vmlinuz-linux /extract/vmlinuz-linux
cp /boot/initramfs-linux.img /extract/initramfs-linux.img

# Stamp a json file which tells people what files are for what.
json='{"kernel": "vmlinuz-linux", "initramfs": "initramfs-linux.img", "rootfs": "rootfs.squash"}'
echo $json > /extract/image.json